package cn.tom.service.impl;

import cn.tom.dao.CartDao;
import cn.tom.entity.Cart;
import cn.tom.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CartServiceImpl  implements CartService {
    @Autowired
    private CartDao cartDao;

    @Override
    public int del(int id) {
        return cartDao.del(id);
    }

    @Override
    public int add(Cart cart) {
        int n = 0;
        try{
            n = cartDao.add(cart);
        }catch (Exception e) {
          n =  cartDao.update(cart);
        }
        return n ;
    }


    @Override
    public List<Cart> findByUid(int uid) {
        return cartDao.findByUid(uid);
    }
}
